/*
*    create by wzp 
*    create time 2008-06-10
*
*    function : add id to every cell of table, 
*               the ID is the position of the cell in excel file
*/
function InterfaceAddRowID(dataTableId)
{
    addRowID(document.getElementById(dataTableId));        
}

/*
    function: add rowId to every row of table
*/  
function addRowID(tableObj)
{   
    for(i = 0; i < tableObj.rows.length; i++)
    {       
        for(j = 0; j < tableObj.rows[i].cells.length; j++)
        {           
            var tmTD =  tableObj.rows[i].cells[j];
            if(tmTD != null )
            {
                var id = tmTD.id;
                    
                if(id == null || "" == id)
                {
                    if(j > 0)
                    {
                        var tmObj = tableObj.rows[i].cells[j - 1];
                        var tmID = tmObj.id;
                        var tmX;
                        var tmY;
                        if(tmID != null && "" != tmID)
                        {
                            var tmArray = tmID.split(",");
                            tmX = tmArray[0];
                            tmY = tmArray[1];
                        }
                        
                        var tmIntX = i + 1;
                        var tmIntY = 0;
                        if(tmObj.colSpan > 0)
                        {
                        
                            tmIntY = 0 + parseInt(tmObj.colSpan )+ parseInt(tmY);
                        }
                        else
                        {
                            tmIntY = 0 + parseInt(tmY) + 1;
                        }
                        tmTD.id = "" + tmIntX + "," + tmIntY;
                    }
                    else
                    {                       
                        var tmIntX = i + 1;
                        var tmIntY = j + 1;             
                        tmTD.id = "" + tmIntX + "," + tmIntY;                                           
                    }
                    
                }
                                
                var tmRowSpan = tmTD.rowSpan;
                var tmColSpan = tmTD.colSpan;
                if("" == tmColSpan || null == tmColSpan)
                {
                    tmColSpan = 0;
                } 

                if("" == tmRowSpan || null == tmRowSpan)
                {
                    tmRowSpan = 0;
                } 
                
                if(tmRowSpan > 1)
                {   
                
                    for(k = 1; k < tmRowSpan; k++)
                    {
                        if( i + k  < tableObj.rows.length && j + tmColSpan < tableObj.rows[i + k].cells.length)
                        { 
                    
                            var tmTD2 = tableObj.rows[i + k].cells[0];
    

                            if(tmTD2 != null && "" != tmTD2)
                            {
                                var id2 = tmTD2.id;
                                
                                if(j >= 0)
                                {
                                    var tmObj = tableObj.rows[i].cells[j];                              
                                    var tmID = tmObj.id;
                                    var tmX;
                                    var tmY;
                                    if(tmID != null && "" != tmID)
                                    {
                                        var tmArray = tmID.split(",");
                                        tmX = tmArray[0];
                                        tmY = tmArray[1];
                                    }

                                    var tmIntX = i + k + 1;
                                    var tmIntY = 0;
                                    if(tmObj.colSpan > 0)
                                    {
                                    
                                        tmIntY = 0 + parseInt(tmObj.colSpan )+ parseInt(tmY);
                                    }
                                    else
                                    {
                                        tmIntY = 0 + parseInt(tmY) + 1;
                                    }
                                    tmTD2.id = "" + tmIntX + "," + tmIntY;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

/*
*    create by wzp 
*    create time 2008-06-10

    function ：get value from table;
    param    ：

               xPos   : x position of value;
               yPos   : y position of value;

    !notice: the xPos and Y yPos are the position of the value 
             in excel file, so this function should find the 
             real position in the table of html,then return the
             value;
*/
function getValueHtml(xPos , yPos)
{
    var testObj = document.getElementById("" + xPos + "," + yPos + "");
    return testObj.innerText;
}

/**
*    create by wzp 
*    create time 2008-06-10
*    function ：get values from table;
*    param    ：

*               Pos   : start position of values;
*               Dire  : the extended direction of data 1: X; 2:Y; 
*    
*    return   : an array of values.
*/
function getValueS(Pos, Dire)
{
    var xStrArrTmp = new Array();
    xStrArrTmp.length=0;
    
    var tmPos = Pos;
    var tm = Pos.split(",");
    if(tm == null || tm.length < 2)
    {
        return null;
    } 
    var x = parseInt(tm[0]);
    var y = parseInt(tm[1]);
    if("1" == Dire)
    {
        for( k = 0; k >= 0; k++)
        {
            var testObj = document.getElementById("" + x + "," + y + "");
            y = y + 1;
            if(testObj == null )
                break;
                
            if("" ==  testObj.innerText || null == testObj.innerText)
            {                   
                xStrArrTmp[xStrArrTmp.length] = 0;
            }
            else
            {
                xStrArrTmp[xStrArrTmp.length] = testObj.innerText;              
            }
        }
    }
    if("2" == Dire)
    {
        for( k = 0; k >= 0; k++)
        {       
            var testObj = document.getElementById("" + x + "," + y + "");
            x = x + 1;
            if(testObj == null )
                break;                
            if("" ==  testObj.innerText || null == testObj.innerText)
            {                   
                xStrArrTmp[xStrArrTmp.length] = 0;
            }
            else
            {
                //判断表单数据值如果带%则去掉
                var v =testObj.innerText;
               // alert(v);
                xStrArrTmp[xStrArrTmp.length] = testObj.innerText;                  
            }
        }
    }    
    
    return xStrArrTmp;
}

